#include "UdpServe.h"
#include "comm.h"
#include "User.h"
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cerr << "Usage: " << argv[0] << " localport" << std::endl;
        Die(1);
    }
    // std::string ip = argv[1];
    uint16_t port = std::stoi(argv[1]);

    ENABLE_CONSOLE_LOG();
    std::shared_ptr<UserManager> um = std::make_shared<UserManager>();
    std::unique_ptr<UdpServe> str_ptr = std::make_unique<UdpServe>(port);
    str_ptr->RegisterService([&um](IntAddr &id)
                             { um->Adduser(id); },
                             [&um](int sockfd, const std::string &message)
                             { um->Router(sockfd, message); },
                             [&um](IntAddr &id)
                             { um->DelUser(id); });
    str_ptr->InitServe();
    str_ptr->Start();
    return 0;
}